import 'package:flutter/material.dart';
import 'package:myapp/not_found_page.dart';
import 'package:myapp/components/Logger/loggers.dart';
import 'package:myapp/page/Chat/chat_page.dart';
import 'package:myapp/page/Login/login_page.dart';
//引入文件
import 'package:myapp/page/main_page.dart';

//配置路由规则
final routes = {
  '/': (context) => const MainPage(),
  '/chat': (context) => const Chat(),
  '/login': (context) => const LoginPage()
};

// 如果你要把路由抽离出去，必须写下面这一堆的代码，不用理解什么意思
var onGenerateRoute = (RouteSettings settings) {
  // 统一处理
  return MaterialPageRoute(builder: (context) => const NotFoundPage());
};

class MyRouteObserver extends NavigatorObserver {
  @override
  void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
    // 在路由被push时调用
    super.didPush(route, previousRoute);
    logger.i('Route pushed: ${route.settings.name}');
    // 这里可以加入拦截逻辑
  }

  @override
  void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
    // 在路由被pop时调用
    super.didPop(route, previousRoute);
    logger.i('Route popped: ${route.settings.name}');
    // 这里可以加入拦截逻辑
  }

  @override
  void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
    // 在路由被替换时调用
    super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
    logger.i(
        'Route replaced: ${oldRoute?.settings.name} -> ${newRoute?.settings.name}');
    // 这里可以加入拦截逻辑
  }

  // 可以监听其它路由事件，根据需要重写其它方法
}
